package com.ly.web.controller.erp;

import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ly.heart.domain.dto.SaleMarkedDto;
import com.ly.heart.domain.vo.SaleMarkedPriceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.heart.domain.SaleMarkedPriceEntity;
import com.ly.heart.service.ISaleMarkedPriceService;
import com.ly.common.utils.poi.ExcelUtil;

import javax.annotation.Resource;

/**
 * 销售价目Controller
 *
 * @author wutao
 * @date 2024-07-15
 */
@Api(value = "markenPrice", tags = "销售价目")
@RestController
@RequestMapping("/heart/markenPrice")
public class SaleMarkedPriceController extends BaseController {

    @Resource
    private ISaleMarkedPriceService saleMarkedPriceService;
    /**
     * 查询销售价目列表
     */
    @PreAuthorize("@ss.hasPermi('heart:markenPrice:list')")
    @GetMapping("/list")
    @ApiOperation("查询销售价目列表")
    public AjaxResult list(SaleMarkedDto saleMarkedPrice) {
        IPage<SaleMarkedPriceVo> saleMarkedPriceVoIPage = saleMarkedPriceService.selectSaleMarkedPriceListNew(saleMarkedPrice);
        return AjaxResult.success(saleMarkedPriceVoIPage);
    }

    /**
     * 导出销售价目列表
     */
    @PreAuthorize("@ss.hasPermi('heart:markenPrice:export')")
    @Log(title = "销售价目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出销售价目列表")
    public AjaxResult export(SaleMarkedPriceEntity saleMarkedPrice) {
        List<SaleMarkedPriceEntity> list = saleMarkedPriceService.selectSaleMarkedPriceList(saleMarkedPrice);
        ExcelUtil<SaleMarkedPriceEntity> util = new ExcelUtil<SaleMarkedPriceEntity>(SaleMarkedPriceEntity.class);
        return util.exportExcel(list, "markenPrice");
    }

    /**
     * 获取销售价目详细信息
     */
    @PreAuthorize("@ss.hasPermi('heart:markenPrice:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取销售价目详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        SaleMarkedPriceEntity saleMarkedPriceEntity = saleMarkedPriceService.selectSaleMarkedPriceById(id);
        return AjaxResult.success(saleMarkedPriceEntity);
    }

//    /**
//     * 新增销售价目
//     */
//    @PreAuthorize("@ss.hasPermi('heart:markenPrice:add')")
//    @Log(title = "销售价目", businessType = BusinessType.INSERT)
//    @PostMapping
//    @ApiOperation("新增销售价目")
//    public AjaxResult add(@RequestBody SaleMarkedPriceEntity saleMarkedPrice) {
//        AjaxResult ajaxResult = saleMarkedPriceService.insertSaleMarkedPrice(saleMarkedPrice);
//        return ajaxResult;
//    }


    @PreAuthorize("@ss.hasPermi('heart:markenPrice:add')")
    @Log(title = "暂存销售价目", businessType = BusinessType.INSERT)
    @PostMapping("draft")
    @ApiOperation("暂存销售价目")
    public AjaxResult draft(@RequestBody SaleMarkedPriceEntity saleMarkedPrice) {
        AjaxResult ajaxResult = saleMarkedPriceService.draft(saleMarkedPrice);
        return AjaxResult.success(ajaxResult);
    }

    @PreAuthorize("@ss.hasPermi('heart:markenPrice:add')")
    @Log(title = "提交销售报价单", businessType = BusinessType.INSERT)
    @PostMapping("submit")
    @ApiOperation("提交销售报价单")
    public AjaxResult submit(@RequestBody SaleMarkedPriceEntity saleMarkedPrice) {
        AjaxResult ajaxResult = saleMarkedPriceService.submit(saleMarkedPrice);
        return AjaxResult.success(ajaxResult);
    }

    /**
     * 修改销售价目
     */
    @PreAuthorize("@ss.hasPermi('heart:markenPrice:edit')")
    @Log(title = "销售价目", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改销售价目")
    public AjaxResult edit(@RequestBody SaleMarkedPriceEntity saleMarkedPrice) {
        return saleMarkedPriceService.updateSaleMarkedPrice(saleMarkedPrice);
    }

    /**
     * 删除销售价目
     */
    @PreAuthorize("@ss.hasPermi('heart:markenPrice:remove')")
    @Log(title = "销售价目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除销售价目")
    public AjaxResult remove(@PathVariable String[] ids) {
        return saleMarkedPriceService.deleteSaleMarkedPriceByIds(ids);
    }
}
